//
//  NewsTagsManager.m
//  suRead
//
//  Created by lidi on 2018/1/3.
//  Copyright © 2018年 bao. All rights reserved.
//

#import "NewsTagsManager.h"
#import "M_tags.h"

@interface NewsTagsManager()

@property(strong,nonatomic)NSArray<M_tags *> *userTags;
@property(strong,nonatomic)NSArray<M_tags *> *allTags;

@end

@implementation NewsTagsManager

+ (instancetype)shared {
    static NewsTagsManager *sharedManager = nil;
    static dispatch_once_t predicate;
    dispatch_once(&predicate, ^{
        sharedManager = [self new];
        NSString *doc = [NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES) objectAtIndex:0];
        NSString *userTagPath = [doc stringByAppendingPathComponent:@"UserTags"];
        sharedManager.userTags = [NSArray arrayWithContentsOfFile:userTagPath];
    });
    return sharedManager;
}

- (void)saveUserTags {
    NSString *doc = [NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES) objectAtIndex:0];
    NSString *userTagPath = [doc stringByAppendingPathComponent:@"UserTags"];
    [self.userTags writeToFile:userTagPath atomically:YES];
}

@end
